package svc

import (
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"share/internal/config"
	"share/models"
)

type ServiceContext struct {
	Config                config.Config
	Conn                  sqlx.SqlConn
	ShareModel            models.ShareModel
	ShareResourceModel    models.ShareResourceModel
	ShareAccessModel      models.ShareAccessModel
	ShareAggregationModel models.ShareAggregationModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewSqlConn(c.Database.Driver, c.Database.DSN)
	return &ServiceContext{
		Config:                c,
		Conn:                  conn,
		ShareModel:            models.NewShareModel(conn, c.Cache),
		ShareResourceModel:    models.NewShareResourceModel(conn, c.Cache),
		ShareAccessModel:      models.NewShareAccessModel(conn, c.Cache),
		ShareAggregationModel: models.NewShareAggregationModel(conn),
	}
}
